<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Java基础学习（3） | SuperXCR</title><meta name="author" content="SuperXCR"><meta name="copyright" content="SuperXCR"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="创建对象1.1 Java 包管理器Java当中导入包语句  import 包含 + 类名    包名+类名组成了完整的包路径 import123456789101112import java.time.LocalDate;&#x2F;&#x2F;包路径public class DateTest &amp;#123;  public static void main(String[] args) &amp;#123;    &#x2F;&#x2F; 得到">
<meta property="og:type" content="article">
<meta property="og:title" content="Java基础学习（3）">
<meta property="og:url" content="https://liqur.xyz/SuperXCR/8eb491b8.html">
<meta property="og:site_name" content="SuperXCR">
<meta property="og:description" content="创建对象1.1 Java 包管理器Java当中导入包语句  import 包含 + 类名    包名+类名组成了完整的包路径 import123456789101112import java.time.LocalDate;&#x2F;&#x2F;包路径public class DateTest &amp;#123;  public static void main(String[] args) &amp;#123;    &#x2F;&#x2F; 得到">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney4.jpg">
<meta property="article:published_time" content="2022-08-31T02:00:03.000Z">
<meta property="article:modified_time" content="2022-09-15T13:50:34.408Z">
<meta property="article:author" content="SuperXCR">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney4.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://liqur.xyz/SuperXCR/8eb491b8.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Java基础学习（3）',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-09-15 21:50:34'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">16</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney4.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="SuperXCR"><span class="site-name">SuperXCR</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Java基础学习（3）</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-08-31T02:00:03.000Z" title="发表于 2022-08-31 10:00:03">2022-08-31</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-09-15T13:50:34.408Z" title="更新于 2022-09-15 21:50:34">2022-09-15</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Java/">Java</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Java基础学习（3）"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="创建对象"><a href="#创建对象" class="headerlink" title="创建对象"></a>创建对象</h3><h4 id="1-1-Java-包管理器"><a href="#1-1-Java-包管理器" class="headerlink" title="1.1 Java 包管理器"></a>1.1 Java 包管理器</h4><p>Java当中导入包语句  import 包含 + 类名    包名+类名组成了完整的包路径</p>
<h5 id="import"><a href="#import" class="headerlink" title="import"></a>import</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.time.LocalDate;<span class="comment">//包路径</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">DateTest</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">    <span class="comment">// 得到当前的完整时间</span></span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">now</span> <span class="operator">=</span> LocalDate.now();<span class="comment">//now()指服务器的时间</span></span><br><span class="line">    <span class="comment">// 打印出时间</span></span><br><span class="line">    System.out.println(now.toString());</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="DateTimeFormatter-自定义时间日期格式"><a href="#DateTimeFormatter-自定义时间日期格式" class="headerlink" title="DateTimeFormatter 自定义时间日期格式"></a>DateTimeFormatter 自定义时间日期格式</h5><p>方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//前提把time转换成字符串</span></span><br><span class="line"><span class="type">DateTimeFormatter</span> <span class="variable">df</span> <span class="operator">=</span> DateTimeFormatter.ofpattern(<span class="string">&quot;yyyy年MM月dd日&quot;</span>);</span><br><span class="line"><span class="type">String</span> <span class="variable">timeStr</span> <span class="operator">=</span> df.format(time);</span><br><span class="line">System.out.println(timeStr);</span><br></pre></td></tr></table></figure>
<p>年份 月份 日 星期 输出</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"></span><br><span class="line">   <span class="type">LocalDate</span> <span class="variable">time</span> <span class="operator">=</span> LocalDate.now();</span><br><span class="line"></span><br><span class="line">   <span class="comment">// 得到当前时间所在年</span></span><br><span class="line">   <span class="type">int</span> <span class="variable">year</span> <span class="operator">=</span> time.getYear();</span><br><span class="line">   System.out.println(<span class="string">&quot;当前年份 &quot;</span> + year);         <span class="comment">//年</span></span><br><span class="line"></span><br><span class="line">   <span class="comment">// 得到当前时间所在月</span></span><br><span class="line">   <span class="type">int</span> <span class="variable">month</span> <span class="operator">=</span> time.getMonth().getValue();</span><br><span class="line">   System.out.println(<span class="string">&quot;当前月份 &quot;</span> + month);        <span class="comment">//月</span></span><br><span class="line"></span><br><span class="line">   <span class="comment">// 得到当前时间在这个月中的天数</span></span><br><span class="line">   <span class="type">int</span> <span class="variable">day</span> <span class="operator">=</span> time.getDayOfMonth();</span><br><span class="line">   System.out.println(<span class="string">&quot;当前日 &quot;</span> + day);            <span class="comment">//天</span></span><br><span class="line"></span><br><span class="line">   <span class="comment">// 得到当前时间所在星期数</span></span><br><span class="line">   <span class="type">int</span> <span class="variable">dayOfWeek</span> <span class="operator">=</span> time.getDayOfWeek().getValue();</span><br><span class="line">   System.out.println(<span class="string">&quot;当前星期 &quot;</span> + dayOfWeek);    <span class="comment">//星期</span></span><br><span class="line"></span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
<p>注:getMonth() 和 getDayWeek() 方法返回值不是具体的数字，而是一个对象(Java官方的设计)，所以必须用getValue()得到具体数字</p>
<h4 id="1-2-时间日期类的运用"><a href="#1-2-时间日期类的运用" class="headerlink" title="1.2 时间日期类的运用"></a>1.2 时间日期类的运用</h4><h5 id="字符串变成LocalDate类型-prase方法"><a href="#字符串变成LocalDate类型-prase方法" class="headerlink" title="字符串变成LocalDate类型 prase方法"></a>字符串变成LocalDate类型 prase方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">date</span> <span class="operator">=</span> <span class="string">&quot;2019-01-01&quot;</span>;</span><br><span class="line"><span class="comment">//把字符串转化为 LocalDate对象，并得到字符串匹配的日期</span></span><br><span class="line"><span class="type">LocalDate</span> <span class="variable">date2</span> <span class="operator">=</span> LocalDate.parse(date);</span><br><span class="line"></span><br><span class="line">System.out.println(date2.toString());</span><br></pre></td></tr></table></figure>
<p>示例②</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">date</span> <span class="operator">=</span> <span class="string">&quot;2019/01/01&quot;</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">DateTimeFormatter</span> <span class="variable">df</span> <span class="operator">=</span> DateTimeFormatter.ofpatern(<span class="string">&quot;yyyy/MM/dd&quot;</span>);</span><br><span class="line"><span class="comment">// 把字符串转化位 LocalDate 对象，并得到字符串匹配的日期</span></span><br><span class="line"><span class="type">LocalDate</span> <span class="variable">date2</span> <span class="operator">=</span> LocalDate.prase(date,df);</span><br><span class="line"></span><br><span class="line">System.out,println(date2.toString());</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="时间日期计算-plusDays-天数-方法"><a href="#时间日期计算-plusDays-天数-方法" class="headerlink" title="时间日期计算 plusDays(天数) 方法"></a>时间日期计算 plusDays(天数) 方法</h5><p>plusDays  加天数</p>
<p>minusDays  减天数</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">    <span class="type">LocalDate</span> <span class="variable">leaveTime</span> <span class="operator">=</span> getLeaveTime(<span class="string">&quot;2019-05-01&quot;</span>, <span class="number">4</span>);</span><br><span class="line">    System.out.println(leaveTime.toString());</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">   * 根据入住时间和入住天数得到离店时间</span></span><br><span class="line"><span class="comment">   *</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> checkInTime</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@param</span> days</span></span><br><span class="line"><span class="comment">   * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">   */</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> LocalDate <span class="title function_">getLeaveTime</span><span class="params">(String checkInTime, <span class="type">int</span> days)</span> &#123;</span><br><span class="line">    <span class="comment">// 把字符串转化为 LocalDate 类型</span></span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">time</span> <span class="operator">=</span> LocalDate.parse(checkInTime);</span><br><span class="line">    <span class="comment">// 使用 plusDays 添加天数，得到新的时间</span></span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">leaveTime</span> <span class="operator">=</span> time.plusDays(days);</span><br><span class="line">    <span class="keyword">return</span> leaveTime;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="两个日期时间的判断"><a href="#两个日期时间的判断" class="headerlink" title="两个日期时间的判断"></a>两个日期时间的判断</h5><p>注意判断方法</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.time.LocalDate;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">DateTest11</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="type">LocalDate</span> <span class="variable">now</span> <span class="operator">=</span> LocalDate.now();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 可以对两个 LocalDate 进行比较，</span></span><br><span class="line">    <span class="comment">// 可以判断一个日期是否在另一个日期之前或之后，</span></span><br><span class="line">    <span class="comment">// 或者判断两个日期是否是同年同月同日。</span></span><br><span class="line"></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isBefore</span> <span class="operator">=</span> now.minusDays(<span class="number">1</span>).isBefore(LocalDate.now());</span><br><span class="line"></span><br><span class="line">    System.out.println(<span class="string">&quot;是否在当天之前：&quot;</span> + isBefore);</span><br><span class="line"></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">isAfter</span> <span class="operator">=</span> now.plusDays(<span class="number">1</span>).isAfter(LocalDate.now());</span><br><span class="line">    System.out.println(<span class="string">&quot;是否在当天之后：&quot;</span> + isAfter);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">// 判断是否是当天</span></span><br><span class="line">    <span class="type">boolean</span> <span class="variable">sameDate</span> <span class="operator">=</span> now.isEqual(LocalDate.now());</span><br><span class="line">    System.out.println(<span class="string">&quot;是否在当天：&quot;</span> + sameDate);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="1-3-面向对象—抽象"><a href="#1-3-面向对象—抽象" class="headerlink" title="1.3 面向对象—抽象"></a>1.3 面向对象—抽象</h4><p>对象的建立</p>
<p>创建Java类文件有四个规范需要遵守</p>
<ul>
<li>文件名由 类名 + .java组成，比如 HelloWorld.java</li>
<li>类名遵循大驼峰命名法，首字母大写，另外类名里不能有中文和特殊符号(比如:&amp;,#,@,*，等)，只有字母和数字。比如： HelloWorld,Text,Text40</li>
<li>Java 类内容遵守固定格式</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> class 类名称&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="1-4-面向对象-—-包"><a href="#1-4-面向对象-—-包" class="headerlink" title="1.4 面向对象 — 包"></a>1.4 面向对象 — 包</h4><h5 id="创建包和包下面的类"><a href="#创建包和包下面的类" class="headerlink" title="创建包和包下面的类"></a>创建包和包下面的类</h5><p>com.superxcr.text   对应 str/main/java/com/superxcr/text</p>
<p>注意包名输入</p>
<p>SuperXCR域名：liqur.xyz</p>
<p>包名：com.superxcr</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">com.superxcr.testl.Hello.java</span><br><span class="line">包名：com.youkeda.text</span><br><span class="line"><span class="keyword">package</span> com.superxcr.test;<span class="comment">//包，一般只有一个，且在第一行</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Hello</span> &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="如何引入自定义的类"><a href="#如何引入自定义的类" class="headerlink" title="如何引入自定义的类"></a>如何引入自定义的类</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.superxcr.test;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> java.time.LocalDate;</span><br><span class="line"><span class="keyword">import</span> java.time.format.DateTimeFormatter;</span><br><span class="line"><span class="comment">//引入 House 类对象</span></span><br><span class="line"><span class="keyword">import</span> com.superxcr.model.House;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Hello</span> &#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="1-5-面向对象—属性-方法"><a href="#1-5-面向对象—属性-方法" class="headerlink" title="1.5 面向对象—属性/方法"></a>1.5 面向对象—属性/方法</h4><p>特征称为 <strong>对象属性</strong> 行为称为 <strong>对象方法</strong> </p>
<p>完整抽象过程分别是抽象对象名称，对象属性，对象方法。</p>
<h5 id="对象属性"><a href="#对象属性" class="headerlink" title="对象属性"></a>对象属性</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">House</span> &#123;</span><br><span class="line">    <span class="comment">// 房子的颜色是绿色</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">String</span> <span class="variable">color</span> <span class="operator">=</span> <span class="string">&quot;green&quot;</span>;</span><br><span class="line">    <span class="comment">// 房子的卧室有2间</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">int</span> <span class="variable">bedRooms</span> <span class="operator">=</span> <span class="number">2</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>public 代表公共变量的意思。除了public，还有protected,private</p>
<h5 id="对象方法"><a href="#对象方法" class="headerlink" title="对象方法"></a>对象方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">House</span> &#123;</span><br><span class="line">    <span class="comment">// 房子的颜色是绿色</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">String</span> <span class="variable">color</span> <span class="operator">=</span> <span class="string">&quot;green&quot;</span>;</span><br><span class="line">    <span class="comment">// 房子的卧室有2间</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">int</span> <span class="variable">bedRooms</span> <span class="operator">=</span> <span class="number">2</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 打开水龙头</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">runWater</span><span class="params">()</span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 打开电灯</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">turnLightsOn</span><span class="params">()</span>&#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>没有static的方法就叫做对象方法，有static的方法就称为静态方法。</p>
<p>例如</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * 打开电灯</span><br><span class="line"> */</span><br><span class="line">public void turnLightsOn()&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="1-6-实例化对象"><a href="#1-6-实例化对象" class="headerlink" title="1.6 实例化对象"></a>1.6 实例化对象</h4><h5 id="实例化"><a href="#实例化" class="headerlink" title="实例化"></a>实例化</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//我的房子</span></span><br><span class="line"><span class="type">House</span> <span class="variable">myHouse</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">House</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">//你的房子</span></span><br><span class="line"><span class="type">House</span> <span class="variable">youHouse</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">House</span>();</span><br><span class="line"></span><br><span class="line"><span class="comment">//她的房子</span></span><br><span class="line"><span class="type">House</span> <span class="variable">herHouse</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">House</span>();</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>在实例化后才可以执行命令</p>
<p>如</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">youHouse.tirnLightOn();</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">herHouse.color = <span class="string">&quot;red&quot;</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="构造函数"><a href="#构造函数" class="headerlink" title="构造函数"></a>构造函数</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> 构造函数();</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>①它的类名是和类名一样</p>
<p>  比如House.java这个类的构造函数名称就是House，绝大多数情况下构造函数都是由Java系统自动创建</p>
<p>②构造函数这个方法是没有返回值的</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">House</span>&#123;</span><br><span class="line">    <span class="comment">//这就是默认的构造函数</span></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">House</span><span class="params">()</span>&#123;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>③构造函数一般配合实例化一起使用的，可以把构造函数当作类对象的初始化方法</p>
<h4 id="1-7-构造函数"><a href="#1-7-构造函数" class="headerlink" title="1.7 构造函数"></a>1.7 构造函数</h4><h5 id="带参数构造函数"><a href="#带参数构造函数" class="headerlink" title="带参数构造函数"></a>带参数构造函数</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">House</span> <span class="variable">myHouse</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">House</span>();</span><br><span class="line">myHouse.color = <span class="string">&quot;red&quot;</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">myHouse.color = <span class="string">&quot;red&quot;</span>;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">House</span> &#123;</span><br><span class="line">    <span class="comment">// 房子的颜色是绿色</span></span><br><span class="line">    <span class="keyword">public</span> <span class="type">String</span> <span class="variable">color</span> <span class="operator">=</span> <span class="string">&quot;green&quot;</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 自定义一个带 color 参数的构造函数</span></span><br><span class="line">    <span class="keyword">public</span> <span class="title function_">House</span><span class="params">(String color)</span>&#123;</span><br><span class="line">      <span class="built_in">this</span>.color = color;<span class="comment">//等同于myHouse.color = &quot;red&quot;;</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="File"><a href="#File" class="headerlink" title="File"></a>File</h5><p>首先要 import java.io.File</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 实例化一个文件实例，指向到 d:/img/a.png 文件</span></span><br><span class="line"><span class="type">File</span> <span class="variable">file</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">File</span>(<span class="string">&quot;d:/img/a.png&quot;</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//根据parent路径名字符串和child路径名字符串创建一个新 File 实例</span></span><br><span class="line">File(String parent, String child)</span><br><span class="line"></span><br><span class="line"><span class="comment">//通过给定的父文件对象和子路径名字符串创建一个新的File实例</span></span><br><span class="line">File(File parent, String child)</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 返回字节数</span></span><br><span class="line"><span class="keyword">public</span> <span class="type">long</span> <span class="title function_">length</span><span class="params">()</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//得到文件大小的字节数</span></span><br><span class="line"><span class="type">long</span> <span class="variable">size</span> <span class="operator">=</span> file.length();</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="File-对象的其他方法："><a href="#File-对象的其他方法：" class="headerlink" title="File 对象的其他方法："></a>File 对象的其他方法：</h5><p>​            | | |</p>
<p>​            v v v</p>
<h5 id="详细请看最下方"><a href="#详细请看最下方" class="headerlink" title="详细请看最下方"></a>详细请看最下方</h5><h4 id="1-8-ArrayList"><a href="#1-8-ArrayList" class="headerlink" title="1.8 ArrayList"></a>1.8 ArrayList</h4><h5 id="ArrayList语法"><a href="#ArrayList语法" class="headerlink" title="ArrayList语法"></a>ArrayList语法</h5><p>ArrayList 本质上就是一个动态组对象，可以方便的存储集合对象，一般会把同类型的数据存储在ArrayList里，使用ArryayList就要实例化，使用new关键词，并且要指定对象</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 这里的 Java 对象类型可以是任意的对象类型</span></span><br><span class="line"><span class="comment">// 比如 String、Integer、House 等</span></span><br><span class="line"><span class="comment">// 这里的 &lt;&gt; 是 Java 泛型的规范,记住这个语法就行了</span></span><br><span class="line">ArrayList&lt;Java 对象类型&gt; list = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>注意一下，ArrayList这个对象放在java.util包下，所以要用import</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="Add方法"><a href="#Add方法" class="headerlink" title="Add方法"></a>Add方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">ArrayListTest1</span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line">    <span class="comment">// 创建一个 ArrayList 存储字符串集合</span></span><br><span class="line">    ArrayList&lt;String&gt; strs = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 添加数据到 ArrayList 实例里</span></span><br><span class="line">    strs.add(<span class="string">&quot;张三&quot;</span>);</span><br><span class="line">    strs.add(<span class="string">&quot;李四&quot;</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="get-size方法"><a href="#get-size方法" class="headerlink" title="get/size方法"></a>get/size方法</h5><p>ArrayList 是动态数组，具备数组特点</p>
<ul>
<li><p>可以获取长度</p>
</li>
<li><p>可以根据索引获取具体值get(索引)，ArrayList的索引是从0开始的</p>
<p>一般用index来索引</p>
</li>
</ul>
<h5 id="for循环的两种写法"><a href="#for循环的两种写法" class="headerlink" title="for循环的两种写法"></a>for循环的两种写法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i&lt;size;i++)&#123;</span><br><span class="line">     <span class="comment">// 根据索引获取值，值的类型是 String</span></span><br><span class="line">     <span class="type">String</span> <span class="variable">str</span> <span class="operator">=</span> strs.get(i);</span><br><span class="line">     System.out.println(str);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 使用 for 循环迭代每一条记录</span></span><br><span class="line">  <span class="keyword">for</span>(String str : strs)&#123;</span><br><span class="line">     System.out.println(str);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>分析</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">ArrayList&lt;String&gt; strs = <span class="keyword">new</span> <span class="title class_">ArrayList</span>&lt;&gt;();</span><br><span class="line"><span class="keyword">for</span>(String str : strs)&#123;</span><br><span class="line">  System.out.println(str);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>( 集合变量的类型 变量名称 : 集合变量 )</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>格式</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span>(String str : strs)&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h5 id="Map"><a href="#Map" class="headerlink" title="Map"></a>Map</h5><p><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/java-map1.png" alt="img"></p>
<p>Map(映射)是遵循key:value这样的形式的集合。key，value的类型可以是任何Java对象</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.Map;</span><br><span class="line"><span class="keyword">import</span> java.util.HashMap;</span><br><span class="line"></span><br><span class="line"><span class="comment">// key value 得是 Java 类型</span></span><br><span class="line">Map&lt;key,value&gt; map = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 实例化Map对象</span></span><br><span class="line">Map&lt;Integer,String&gt; map = <span class="keyword">new</span> <span class="title class_">HashMap</span>&lt;&gt;();</span><br><span class="line"></span><br><span class="line">map.put(<span class="number">1</span>,<span class="string">&quot;Monday&quot;</span>);</span><br><span class="line">map.put(<span class="number">2</span>,<span class="string">&quot;Tuesday&quot;</span>);</span><br><span class="line">map.put(<span class="number">3</span>,<span class="string">&quot;Wednesday&quot;</span>);</span><br><span class="line">map.put(<span class="number">4</span>,<span class="string">&quot;Thursday&quot;</span>);</span><br><span class="line">map.put(<span class="number">5</span>,<span class="string">&quot;Friday&quot;</span>);</span><br><span class="line">map.put(<span class="number">6</span>,<span class="string">&quot;Saturday&quot;</span>);</span><br><span class="line">map.put(<span class="number">7</span>,<span class="string">&quot;Sunday&quot;</span>);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>map.get(key)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">String</span> <span class="variable">weekText</span> <span class="operator">=</span> map.get(<span class="number">3</span>);</span><br><span class="line">System.out.println(weekText);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="variable">size</span> <span class="operator">=</span> map.size();</span><br><span class="line">System.out.println(size);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>Map遍历</p>
<p>因为是key ：value格式</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> (Map.Entry&lt;Integer,String&gt; entry : map.entrySet())&#123;</span><br><span class="line"></span><br><span class="line">  System.out.println(<span class="string">&quot;Key = &quot;</span> + entry.getKey() +</span><br><span class="line">                 <span class="string">&quot;, Value = &quot;</span> + entry.getValue());</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>调用reply方法传入send()方法接受信息</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> String <span class="title function_">send</span><span class="params">(String message)</span> &#123;</span><br><span class="line">        <span class="type">String</span> <span class="variable">reply</span> <span class="operator">=</span> robot.reply(message);</span><br><span class="line">        <span class="keyword">return</span> reply;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="File-对象的其他方法：-1"><a href="#File-对象的其他方法：-1" class="headerlink" title="File 对象的其他方法："></a>File 对象的其他方法：</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><span class="line">File 对象的其他方法</span><br><span class="line"><span class="number">1</span> <span class="keyword">public</span> String <span class="title function_">getName</span><span class="params">()</span></span><br><span class="line">返回由此抽象路径名表示的文件或目录的名称。</span><br><span class="line"></span><br><span class="line"><span class="number">2</span> <span class="keyword">public</span> String <span class="title function_">getParent</span><span class="params">()</span>、</span><br><span class="line">返回此抽象路径名的父路径名的路径名字符串，如果此路径名没有指定父目录，则返回 <span class="literal">null</span>。</span><br><span class="line"></span><br><span class="line"><span class="number">3</span> <span class="keyword">public</span> File <span class="title function_">getParentFile</span><span class="params">()</span></span><br><span class="line">返回此抽象路径名的父路径名的抽象路径名，如果此路径名没有指定父目录，则返回 <span class="literal">null</span>。</span><br><span class="line"></span><br><span class="line"><span class="number">4</span> <span class="keyword">public</span> String <span class="title function_">getPath</span><span class="params">()</span></span><br><span class="line">将此抽象路径名转换为一个路径名字符串。</span><br><span class="line"></span><br><span class="line"><span class="number">5</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">isAbsolute</span><span class="params">()</span></span><br><span class="line">测试此抽象路径名是否为绝对路径名。</span><br><span class="line"></span><br><span class="line"><span class="number">6</span> <span class="keyword">public</span> String <span class="title function_">getAbsolutePath</span><span class="params">()</span></span><br><span class="line">返回抽象路径名的绝对路径名字符串。</span><br><span class="line"></span><br><span class="line"><span class="number">7</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">canRead</span><span class="params">()</span></span><br><span class="line">测试应用程序是否可以读取此抽象路径名表示的文件。</span><br><span class="line"></span><br><span class="line"><span class="number">8</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">canWrite</span><span class="params">()</span></span><br><span class="line">测试应用程序是否可以修改此抽象路径名表示的文件。</span><br><span class="line"></span><br><span class="line"><span class="number">9</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">exists</span><span class="params">()</span></span><br><span class="line">测试此抽象路径名表示的文件或目录是否存在。</span><br><span class="line"></span><br><span class="line"><span class="number">10</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">isDirectory</span><span class="params">()</span></span><br><span class="line">测试此抽象路径名表示的文件是否是一个目录。</span><br><span class="line"></span><br><span class="line"><span class="number">11</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">isFile</span><span class="params">()</span></span><br><span class="line">测试此抽象路径名表示的文件是否是一个标准文件。</span><br><span class="line"></span><br><span class="line"><span class="number">12</span> <span class="keyword">public</span> <span class="type">long</span> <span class="title function_">lastModified</span><span class="params">()</span></span><br><span class="line">返回此抽象路径名表示的文件最后一次被修改的时间。</span><br><span class="line"></span><br><span class="line"><span class="number">13</span> <span class="keyword">public</span> <span class="type">long</span> <span class="title function_">length</span><span class="params">()</span></span><br><span class="line">返回由此抽象路径名表示的文件的长度。</span><br><span class="line"></span><br><span class="line"><span class="number">14</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">createNewFile</span><span class="params">()</span> <span class="keyword">throws</span> IOException</span><br><span class="line">当且仅当不存在具有此抽象路径名指定的名称的文件时，原子地创建由此抽象路径名指定的一个新的空文件。</span><br><span class="line"></span><br><span class="line"><span class="number">15</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">delete</span><span class="params">()</span></span><br><span class="line">删除此抽象路径名表示的文件或目录。</span><br><span class="line"></span><br><span class="line"><span class="number">16</span> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">deleteOnExit</span><span class="params">()</span></span><br><span class="line">在虚拟机终止时，请求删除此抽象路径名表示的文件或目录。</span><br><span class="line"></span><br><span class="line"><span class="number">17</span> <span class="keyword">public</span> String[] list()</span><br><span class="line">返回由此抽象路径名所表示的目录中的文件和目录的名称所组成字符串数组。</span><br><span class="line"></span><br><span class="line"><span class="number">18</span> <span class="keyword">public</span> String[] list(FilenameFilter filter)</span><br><span class="line">返回由包含在目录中的文件和目录的名称所组成的字符串数组，这一目录是通过满足指定过滤器的抽象路径名来表示的。</span><br><span class="line"></span><br><span class="line"><span class="number">19</span> <span class="keyword">public</span> File[] listFiles()</span><br><span class="line">返回一个抽象路径名数组，这些路径名表示此抽象路径名所表示目录中的文件。</span><br><span class="line"></span><br><span class="line"><span class="number">20</span> <span class="keyword">public</span> File[] listFiles(FileFilter filter)</span><br><span class="line">返回表示此抽象路径名所表示目录中的文件和目录的抽象路径名数组，这些路径名满足特定过滤器。</span><br><span class="line"></span><br><span class="line"><span class="number">21</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">mkdir</span><span class="params">()</span></span><br><span class="line">创建此抽象路径名指定的目录。</span><br><span class="line"></span><br><span class="line"><span class="number">22</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">mkdirs</span><span class="params">()</span></span><br><span class="line">创建此抽象路径名指定的目录，包括创建必需但不存在的父目录。</span><br><span class="line"></span><br><span class="line"><span class="number">23</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">renameTo</span><span class="params">(File dest)</span></span><br><span class="line">重新命名此抽象路径名表示的文件。</span><br><span class="line"></span><br><span class="line"><span class="number">24</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">setLastModified</span><span class="params">(<span class="type">long</span> time)</span></span><br><span class="line">设置由此抽象路径名所指定的文件或目录的最后一次修改时间。</span><br><span class="line"></span><br><span class="line"><span class="number">25</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">setReadOnly</span><span class="params">()</span></span><br><span class="line">标记此抽象路径名指定的文件或目录，以便只可对其进行读操作。</span><br><span class="line"></span><br><span class="line"><span class="number">26</span> <span class="keyword">public</span> <span class="keyword">static</span> File <span class="title function_">createTempFile</span><span class="params">(String prefix, String suffix, File directory)</span> <span class="keyword">throws</span> IOException</span><br><span class="line">在指定目录中创建一个新的空文件，使用给定的前缀和后缀字符串生成其名称。</span><br><span class="line"></span><br><span class="line"><span class="number">27</span> <span class="keyword">public</span> <span class="keyword">static</span> File <span class="title function_">createTempFile</span><span class="params">(String prefix, String suffix)</span> <span class="keyword">throws</span> IOException</span><br><span class="line">在默认临时文件目录中创建一个空文件，使用给定前缀和后缀生成其名称。</span><br><span class="line"></span><br><span class="line"><span class="number">28</span> <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">compareTo</span><span class="params">(File pathname)</span></span><br><span class="line">按字母顺序比较两个抽象路径名。</span><br><span class="line"></span><br><span class="line"><span class="number">29</span> <span class="keyword">public</span> <span class="type">int</span> <span class="title function_">compareTo</span><span class="params">(Object o)</span></span><br><span class="line">按字母顺序比较抽象路径名与给定对象。</span><br><span class="line"></span><br><span class="line"><span class="number">30</span> <span class="keyword">public</span> <span class="type">boolean</span> <span class="title function_">equals</span><span class="params">(Object obj)</span></span><br><span class="line">测试此抽象路径名与给定对象是否相等。</span><br><span class="line"></span><br><span class="line"><span class="number">31</span> <span class="keyword">public</span> String <span class="title function_">toString</span><span class="params">()</span></span><br><span class="line">返回此抽象路径名的路径名字符串。</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://liqur.xyz">SuperXCR</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liqur.xyz/SuperXCR/8eb491b8.html">https://liqur.xyz/SuperXCR/8eb491b8.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liqur.xyz" target="_blank">SuperXCR</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Java/">Java</a></div><div class="post_share"><div class="social-share" data-image="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney4.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/SuperXCR/3ce8deb9.html" title="HTML基础学习"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/h2.webp" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">HTML基础学习</div></div></a></div><div class="next-post pull-right"><a href="/SuperXCR/3608f6dd.html" title="Java基础学习（2）"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney5.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Java基础学习（2）</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/SuperXCR/3608f6dd.html" title="Java基础学习（2）"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney5.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-31</div><div class="title">Java基础学习（2）</div></div></a></div><div><a href="/SuperXCR/24bd5933.html" title="Java基础学习（1）"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/java6.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-31</div><div class="title">Java基础学习（1）</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">SuperXCR</div><div class="author-info__description">今日事，今日毕</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">16</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.</span> <span class="toc-text">创建对象</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-Java-%E5%8C%85%E7%AE%A1%E7%90%86%E5%99%A8"><span class="toc-number">1.1.</span> <span class="toc-text">1.1 Java 包管理器</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#import"><span class="toc-number">1.1.1.</span> <span class="toc-text">import</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#DateTimeFormatter-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%97%B6%E9%97%B4%E6%97%A5%E6%9C%9F%E6%A0%BC%E5%BC%8F"><span class="toc-number">1.1.2.</span> <span class="toc-text">DateTimeFormatter 自定义时间日期格式</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-2-%E6%97%B6%E9%97%B4%E6%97%A5%E6%9C%9F%E7%B1%BB%E7%9A%84%E8%BF%90%E7%94%A8"><span class="toc-number">1.2.</span> <span class="toc-text">1.2 时间日期类的运用</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E5%8F%98%E6%88%90LocalDate%E7%B1%BB%E5%9E%8B-prase%E6%96%B9%E6%B3%95"><span class="toc-number">1.2.1.</span> <span class="toc-text">字符串变成LocalDate类型 prase方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%97%B6%E9%97%B4%E6%97%A5%E6%9C%9F%E8%AE%A1%E7%AE%97-plusDays-%E5%A4%A9%E6%95%B0-%E6%96%B9%E6%B3%95"><span class="toc-number">1.2.2.</span> <span class="toc-text">时间日期计算 plusDays(天数) 方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%A4%E4%B8%AA%E6%97%A5%E6%9C%9F%E6%97%B6%E9%97%B4%E7%9A%84%E5%88%A4%E6%96%AD"><span class="toc-number">1.2.3.</span> <span class="toc-text">两个日期时间的判断</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-3-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E2%80%94%E6%8A%BD%E8%B1%A1"><span class="toc-number">1.3.</span> <span class="toc-text">1.3 面向对象—抽象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-4-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1-%E2%80%94-%E5%8C%85"><span class="toc-number">1.4.</span> <span class="toc-text">1.4 面向对象 — 包</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E5%8C%85%E5%92%8C%E5%8C%85%E4%B8%8B%E9%9D%A2%E7%9A%84%E7%B1%BB"><span class="toc-number">1.4.1.</span> <span class="toc-text">创建包和包下面的类</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%A6%82%E4%BD%95%E5%BC%95%E5%85%A5%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E7%B1%BB"><span class="toc-number">1.4.2.</span> <span class="toc-text">如何引入自定义的类</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-5-%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E2%80%94%E5%B1%9E%E6%80%A7-%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.</span> <span class="toc-text">1.5 面向对象—属性&#x2F;方法</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AF%B9%E8%B1%A1%E5%B1%9E%E6%80%A7"><span class="toc-number">1.5.1.</span> <span class="toc-text">对象属性</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AF%B9%E8%B1%A1%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.2.</span> <span class="toc-text">对象方法</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-6-%E5%AE%9E%E4%BE%8B%E5%8C%96%E5%AF%B9%E8%B1%A1"><span class="toc-number">1.6.</span> <span class="toc-text">1.6 实例化对象</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%9E%E4%BE%8B%E5%8C%96"><span class="toc-number">1.6.1.</span> <span class="toc-text">实例化</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-number">1.6.2.</span> <span class="toc-text">构造函数</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-7-%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-number">1.7.</span> <span class="toc-text">1.7 构造函数</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%B8%A6%E5%8F%82%E6%95%B0%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0"><span class="toc-number">1.7.1.</span> <span class="toc-text">带参数构造函数</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#File"><span class="toc-number">1.7.2.</span> <span class="toc-text">File</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#File-%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%85%B6%E4%BB%96%E6%96%B9%E6%B3%95%EF%BC%9A"><span class="toc-number">1.7.3.</span> <span class="toc-text">File 对象的其他方法：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%AF%A6%E7%BB%86%E8%AF%B7%E7%9C%8B%E6%9C%80%E4%B8%8B%E6%96%B9"><span class="toc-number">1.7.4.</span> <span class="toc-text">详细请看最下方</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-8-ArrayList"><span class="toc-number">1.8.</span> <span class="toc-text">1.8 ArrayList</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#ArrayList%E8%AF%AD%E6%B3%95"><span class="toc-number">1.8.1.</span> <span class="toc-text">ArrayList语法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Add%E6%96%B9%E6%B3%95"><span class="toc-number">1.8.2.</span> <span class="toc-text">Add方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#get-size%E6%96%B9%E6%B3%95"><span class="toc-number">1.8.3.</span> <span class="toc-text">get&#x2F;size方法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#for%E5%BE%AA%E7%8E%AF%E7%9A%84%E4%B8%A4%E7%A7%8D%E5%86%99%E6%B3%95"><span class="toc-number">1.8.4.</span> <span class="toc-text">for循环的两种写法</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Map"><span class="toc-number">1.8.5.</span> <span class="toc-text">Map</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#File-%E5%AF%B9%E8%B1%A1%E7%9A%84%E5%85%B6%E4%BB%96%E6%96%B9%E6%B3%95%EF%BC%9A-1"><span class="toc-number">1.9.</span> <span class="toc-text">File 对象的其他方法：</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/7f8be62d.html" title="你不会还不会安装Maven吧"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/SuperXCR/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230310162508.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="你不会还不会安装Maven吧"/></a><div class="content"><a class="title" href="/SuperXCR/7f8be62d.html" title="你不会还不会安装Maven吧">你不会还不会安装Maven吧</a><time datetime="2023-03-10T09:57:23.000Z" title="发表于 2023-03-10 17:57:23">2023-03-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/c24675b4.html" title="MySQL"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/MySQL%E9%85%8D%E7%BD%AE/mysql.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL"/></a><div class="content"><a class="title" href="/SuperXCR/c24675b4.html" title="MySQL">MySQL</a><time datetime="2022-11-21T06:48:00.000Z" title="发表于 2022-11-21 14:48:00">2022-11-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/bfa56f5e.html" title="Navicat_Premium_16破解"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/s1.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Navicat_Premium_16破解"/></a><div class="content"><a class="title" href="/SuperXCR/bfa56f5e.html" title="Navicat_Premium_16破解">Navicat_Premium_16破解</a><time datetime="2022-09-26T02:55:58.000Z" title="发表于 2022-09-26 10:55:58">2022-09-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/b2444a9.html" title="MySQL安装配置"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/MySQL%E9%85%8D%E7%BD%AE/mysql.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL安装配置"/></a><div class="content"><a class="title" href="/SuperXCR/b2444a9.html" title="MySQL安装配置">MySQL安装配置</a><time datetime="2022-09-24T03:30:42.000Z" title="发表于 2022-09-24 11:30:42">2022-09-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/a219e661.html" title="羊了个羊17最新版"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/s6.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="羊了个羊17最新版"/></a><div class="content"><a class="title" href="/SuperXCR/a219e661.html" title="羊了个羊17最新版">羊了个羊17最新版</a><time datetime="2022-09-16T05:18:03.000Z" title="发表于 2022-09-16 13:18:03">2022-09-16</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By SuperXCR</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script>
    // 全局变量声明区域
    var fdata = {
      apiurl: 'https://hexo-friendcircle-api-ai9d4hwad-anzhiyu-c.vercel.app/api',
      initnumber: 20, //【可选】页面初始化展示文章数量
      stepnumber: 10, //【可选】每次加载增加的篇数
      error_img: 'https://npm.elemecdn.com/akilar-candyassets/image/404.gif' //【可选，头像图片加载失败时的默认头像】
    }
    //存入本地存储
    localStorage.setItem("fdatalist",JSON.stringify(fdata))
    </script>
    <script defer src="https://npm.elemecdn.com/hexo-filter-fcircle/assets/js/fetch.min.js"></script><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    if(parent_div_git) {
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var qweather_key = 'b16a1fa0e63c46a4b8f28abfb06ae3fe';
  var gaud_map_key = 'e2b04289e870b005374ee030148d64fd&s=rsv3';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '112.982279,28.19409';
  var clock_default_rectangle_enable = 'false';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><script async src="/js/ali_font.js"></script><!-- hexo injector body_end end --></body></html>